import { defineStore } from 'pinia'

export const useDashboardStore = defineStore('dashboard', {
  state: () => ({
    statistics: {
      userCount: 1234,
      orderCount: 3456,
      salesAmount: 89745,
      stockCount: 5678
    },
    trends: {
      userTrend: 12,
      orderTrend: -5,
      salesTrend: 8,
      stockTrend: 15
    },
    activities: [
      {
        content: '新用户注册：张三',
        timestamp: '2024-01-20 10:00:00',
        type: 'success'
      },
      {
        content: '新订单创建：#12345',
        timestamp: '2024-01-20 09:30:00',
        type: 'primary'
      },
      {
        content: '库存预警：商品A库存不足',
        timestamp: '2024-01-20 09:00:00',
        type: 'warning'
      },
      {
        content: '系统更新完成',
        timestamp: '2024-01-20 08:30:00',
        type: 'info'
      }
    ]
  }),

  getters: {
    getStatistics: (state) => state.statistics,
    getTrends: (state) => state.trends,
    getActivities: (state) => state.activities
  },

  actions: {
    updateStatistics(newStats) {
      this.statistics = { ...this.statistics, ...newStats }
    },
    updateTrends(newTrends) {
      this.trends = { ...this.trends, ...newTrends }
    },
    addActivity(activity) {
      this.activities.unshift(activity)
    }
  }
})